const jwt = require('jsonwebtoken');
module.exports = () => {
    return async (ctx,next) => {
        //登录  注册 不用带token

        let arr = ['/api/login','/api/registry'];

        if(arr.includes(ctx.request.path)){
            await next()
        }else{
            if(ctx.get('token')){
                try{
                    let info = jwt.verify(ctx.get('token'),'1705d');
                    ctx.info = info;
                    await next();
                }catch(e){
                    ctx.body = {
                        code:0,
                        msg:'token过期'
                    }
                }
            }else{
                ctx.body = {
                    code:0,
                    msg:'没有token'
                }
            }
        }
    }
}